<!DOCTYPE html><html><head><meta charset=utf-8><title>H3DU.Camera</title></head><body><h1> H3DU.Camera</h1><p><a href='index.html'>Back to documentation index.</a></p><a name='H3DU.Camera'></a>
<h3> H3DU.Camera(batch, fov, nearZ, farZ, [canvas])</h3>A class for controlling the projection and
view of a 3D scene, in the nature of an abstract "camera".
This class uses the concept of a "camera's position", or where
the camera is located in world space, as well
as a "reference point", or the point in world space that the camera
is looking at.
<p>This class is considered a supplementary class to the
Public Domain HTML 3D Library and is not considered part of that
library. <p>
To use this class, you must include the script "extras/camera.js"; the
class is not included in the "h3du_min.js" file which makes up
the HTML 3D Library. Example:<pre>
&lt;script type="text/javascript" src="extras/camera.js">&lt;/script></pre><h4> Parameters</h4><ul><li><code>batch</code> (Type: <a href="H3DU.Batch3D.html">H3DU.Batch3D</a>)<br>A 3D batch to associate with this camera object. <i>Using a <a href="H3DU.Scene3D.html">H3DU.Scene3D</a> here is deprecated.</i><li><code>fov</code> (Type: number)<br>Vertical field of view, in degrees. Should be less than 180 degrees. (The smaller this number, the bigger close objects appear to be.) See <a href="H3DU.Math.html#H3DU.Math.mat4perspective">H3DU.Math.mat4perspective</a>.<li><code>nearZ</code> (Type: number)<br>The distance from the camera to the near clipping plane. Objects closer than this distance won't be seen. See <a href="H3DU.Math.html#H3DU.Math.mat4perspective">H3DU.Math.mat4perspective</a>. This should be slightly greater than 0.<li><code>farZ</code> (Type: number)<br>The distance from the camera to the far clipping plane. Objects beyond this distance will be too far to be seen. See <a href="H3DU.Math.html#H3DU.Math.mat4perspective">H3DU.Math.mat4perspective</a>.<li><code>canvas</code> (Type: HTMLCanvasElement) (optional)<br>A canvas to associate with this camera object. <i>This argument is deprecated.</i></ul><h3> Methods</h3><ul><li><a href='#H3DU.Camera_getDistance'>getDistance</a><br>Finds the distance from the camera's position to the reference point.<li><a href='#H3DU.Camera_getPosition'>getPosition</a><br>Gets the position of the camera.<li><a href='#H3DU.Camera_getVectorFromCenter'>getVectorFromCenter</a><br>Gets the 3-element vector that points from the reference
point to the camera's position.<li><a href='#H3DU.Camera_moveAngleHorizontal'>moveAngleHorizontal</a><br>Moves the camera to the left or right so that it faces
the same reference point at the same distance.<li><a href='#H3DU.Camera_moveAngleVertical'>moveAngleVertical</a><br>Moves the camera upward or downward so that it faces
the same reference point at the same distance.<li><a href='#H3DU.Camera_moveCenterHorizontal'>moveCenterHorizontal</a><br><b>Deprecated: Use "moveHorizontal" instead.</b><li><a href='#H3DU.Camera_moveCenterVertical'>moveCenterVertical</a><br><b>Deprecated: Use "moveVertical" instead.</b><li><a href='#H3DU.Camera_moveClose'>moveClose</a><br>Moves the camera the given distance, but not too close
to the reference point.<li><a href='#H3DU.Camera_moveForward'>moveForward</a><br>Moves the camera forward the given distance.<li><a href='#H3DU.Camera_moveHorizontal'>moveHorizontal</a><br>Moves the camera horizontally relative to the camera's up vector.<li><a href='#H3DU.Camera_movePosition'>movePosition</a><br><b>Deprecated: Renamed to "setPosition".</b><li><a href='#H3DU.Camera_moveVertical'>moveVertical</a><br>Moves the camera toward or away from the camera's up vector.<li><a href='#H3DU.Camera_setDistance'>setDistance</a><br>Moves the camera a given distance from the reference
point without changing its orientation.<li><a href='#H3DU.Camera_setPosition'>setPosition</a><br>Sets the position of the camera.<li><a href='#H3DU.Camera_turnAngleHorizontal'>turnAngleHorizontal</a><br>Turns the camera to the left or right so that it faces
the same distance from a reference point.<li><a href='#H3DU.Camera_turnAngleVertical'>turnAngleVertical</a><br>Turns the camera upward or downward so that it faces
the same distance from a reference point.<li><a href='#H3DU.Camera_turnHorizontal'>turnHorizontal</a><br><b>Deprecated: Renamed to "moveAngleHorizontal".</b><li><a href='#H3DU.Camera_turnVertical'>turnVertical</a><br><b>Deprecated: Renamed to "moveAngleVertical".</b><li><a href='#H3DU.Camera_update'>update</a><br>Updates information about this camera based
on the state of an input tracker.</ul><a name='H3DU.Camera_getDistance'></a>
<h3> H3DU.Camera#getDistance()</h3>Finds the distance from the camera's position to the reference point.<h4> Return Value</h4>Return value. (Type: number)<a name='H3DU.Camera_getPosition'></a>
<h3> H3DU.Camera#getPosition()</h3>Gets the position of the camera.<h4> Return Value</h4>An array of three numbers giving
the X, Y, and Z coordinates of the camera's position, respectively. (Type: Array.&lt;number>)<a name='H3DU.Camera_getVectorFromCenter'></a>
<h3> H3DU.Camera#getVectorFromCenter()</h3>Gets the 3-element vector that points from the reference
point to the camera's position.<h4> Return Value</h4>The return value as a unit
vector (a <a href="H3DU.Math.html#H3DU.Math.vec3normalize">"normalized" vector</a> with a length of 1).
Returns (0,0,0) if the reference point is the same as the camera's position. (Type: Array.&lt;number>)<a name='H3DU.Camera_moveAngleHorizontal'></a>
<h3> H3DU.Camera#moveAngleHorizontal(angleDegrees)</h3>Moves the camera to the left or right so that it faces
the same reference point at the same distance.<h4> Parameters</h4><ul><li><code>angleDegrees</code> (Type: number)<br>The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera leftward, and negative values rightward. If the coordinate-system is left-handed, vice versa.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_moveAngleVertical'></a>
<h3> H3DU.Camera#moveAngleVertical(angleDegrees)</h3>Moves the camera upward or downward so that it faces
the same reference point at the same distance.<h4> Parameters</h4><ul><li><code>angleDegrees</code> (Type: number)<br>The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera upward, and negative values downward. If the coordinate-system is left-handed, vice versa.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_moveCenterHorizontal'></a>
<h3> H3DU.Camera#moveCenterHorizontal(dist)</h3><p><b>Deprecated: Use "moveHorizontal" instead.</b></p>Moves the camera horizontally relative to the camera's up vector.<h4> Parameters</h4><ul><li><code>dist</code> (Type: number)<br>Distance to move the camera.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_moveCenterVertical'></a>
<h3> H3DU.Camera#moveCenterVertical(dist)</h3><p><b>Deprecated: Use "moveVertical" instead.</b></p>Moves the camera toward or away from the camera's up vector.<h4> Parameters</h4><ul><li><code>dist</code> (Type: number)<br>Distance to move the camera.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_moveClose'></a>
<h3> H3DU.Camera#moveClose(dist)</h3>Moves the camera the given distance, but not too close
to the reference point.<h4> Parameters</h4><ul><li><code>dist</code> (Type: number)<br>The distance to move. Positive values mean forward, and negative distances mean back.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_moveForward'></a>
<h3> H3DU.Camera#moveForward(dist)</h3>Moves the camera forward the given distance.<h4> Parameters</h4><ul><li><code>dist</code> (Type: number)<br>The distance to move. Positive values mean forward, and negative distances mean back.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_moveHorizontal'></a>
<h3> H3DU.Camera#moveHorizontal(dist)</h3>Moves the camera horizontally relative to the camera's up vector.<h4> Parameters</h4><ul><li><code>dist</code> (Type: number)<br>Distance to move the camera.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_movePosition'></a>
<h3> H3DU.Camera#movePosition(cx, cy, cz)</h3><p><b>Deprecated: Renamed to "setPosition".</b></p>Sets the position of the camera.<h4> Parameters</h4><ul><li><code>cx</code> (Type: number)<br>The camera's new X coordinate.<li><code>cy</code> (Type: number)<br>The camera's new Y coordinate.<li><code>cz</code> (Type: number)<br>The camera's new Z coordinate.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_moveVertical'></a>
<h3> H3DU.Camera#moveVertical(dist)</h3>Moves the camera toward or away from the camera's up vector.<h4> Parameters</h4><ul><li><code>dist</code> (Type: number)<br>Distance to move the camera.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_setDistance'></a>
<h3> H3DU.Camera#setDistance(dist)</h3>Moves the camera a given distance from the reference
point without changing its orientation.<h4> Parameters</h4><ul><li><code>dist</code> (Type: number)<br>Positive number giving the distance. If this is less than the near plane distance, the distance will be equal to the near plane distance. Does nothing if the distance is 0 or less.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_setPosition'></a>
<h3> H3DU.Camera#setPosition(cx, [cy], [cz])</h3>Sets the position of the camera.<h4> Parameters</h4><ul><li><code>cx</code> (Type: number)<br>The camera's new X coordinate, or a 3-element vector containing the X, Y, and Z coordinates. In the latter case, "cy" and "cz" can be omitted.<li><code>cy</code> (Type: number) (optional)<br>The camera's new Y coordinate.<li><code>cz</code> (Type: number) (optional)<br>The camera's new Z coordinate.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_turnAngleHorizontal'></a>
<h3> H3DU.Camera#turnAngleHorizontal(angleDegrees)</h3>Turns the camera to the left or right so that it faces
the same distance from a reference point.<h4> Parameters</h4><ul><li><code>angleDegrees</code> (Type: number)<br>The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera rightward, and negative values leftward. If the coordinate-system is left-handed, vice versa.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_turnAngleVertical'></a>
<h3> H3DU.Camera#turnAngleVertical(angleDegrees)</h3>Turns the camera upward or downward so that it faces
the same distance from a reference point.<h4> Parameters</h4><ul><li><code>angleDegrees</code> (Type: number)<br>The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera upward, and negative values downward. If the coordinate-system is left-handed, vice versa.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_turnHorizontal'></a>
<h3> H3DU.Camera#turnHorizontal(angleDegrees)</h3><p><b>Deprecated: Renamed to "moveAngleHorizontal".</b></p>Moves the camera to the left or right so that it faces
the same reference point at the same distance.<h4> Parameters</h4><ul><li><code>angleDegrees</code> (Type: number)<br>The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera leftward, and negative values rightward. If the coordinate-system is left-handed, vice versa.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_turnVertical'></a>
<h3> H3DU.Camera#turnVertical(angleDegrees)</h3><p><b>Deprecated: Renamed to "moveAngleVertical".</b></p>Moves the camera upward or downward so that it faces
the same reference point at the same distance.<h4> Parameters</h4><ul><li><code>angleDegrees</code> (Type: number)<br>The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera upward, and negative values downward. If the coordinate-system is left-handed, vice versa.</ul><h4> Return Value</h4>This object. (Type: <a href="H3DU.Camera.html">H3DU.Camera</a>)<a name='H3DU.Camera_update'></a>
<h3> H3DU.Camera#update([input])</h3>Updates information about this camera based
on the state of an input tracker.<h4> Parameters</h4><ul><li><code>input</code> (Type: <a href="H3DU.InputTracker.html">H3DU.InputTracker</a>) (optional)<br>An input tracker. This method should be called right after the tracker's 'update' method was called. <i>Note that future versions may require this parameter.</i></ul><h4> Return Value</h4>Return value. (Type: Object)<p><a href='index.html'>Back to documentation index.</a></p></body></html>
